﻿using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.ComponentModel.Composition.Primitives;
using System.Linq;
using System.Reflection;
using Caliburn.Micro;
using Example.Entities;
using Example.Frontend.Shell;
using Zero.Frontend;

namespace Example.Frontend
{
    /// <summary>
    /// Main entry class for Caliburn.Micro.
    /// </summary>
    public class Bootstrapper : MefBootstrapper<IShell>
    {
        public Bootstrapper()
        {
            LogManager.GetLog = type => new DebugLog(type);
        }

        protected override void OnUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
        {
            MessageBox.Show(e.Exception.ToString());
        }

        protected override IEnumerable<Assembly> SelectAssemblies()
        {
            var X = base.SelectAssemblies().Union(new[]
                                                     {
                                                         typeof (Customer).Assembly, // Example.Common
                                                         typeof (IShell).Assembly // Example.Frontend
                                                     });

            return X;
        }

        protected override void ConfigureBatch(CompositionBatch batch)
        {
            batch.AddExportedValue<IWindowManager>(new WindowManager());
            batch.AddExportedValue<IEventAggregator>(new EventAggregator());
            batch.AddExportedValue<IMessageBoxService>(new DefaultMessageBoxService());
        }
    }
}
